<?php
    error_reporting(0);
    define('__ROOT__', dirname(dirname(__FILE__)));
    require_once(__ROOT__.'\config\config.php'); 
    require_once(__ROOT__.'\model\db.php');
    require_once(__ROOT__.'\model\products.php');
    require_once(__ROOT__.'\model\categories.php');
    $category = new Categories();
    $categories = $category->select();
?>
<!doctype html>
<html lang="en">

<head>
	<meta charset="utf-8"/>
	<title>Dashboard I Admin Panel</title>
	
	<link rel="stylesheet" href="../css/layout.css" type="text/css" media="screen" />
	<!--[if lt IE 9]>
	<link rel="stylesheet" href="css/ie.css" type="text/css" media="screen" />
	<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
	<![endif]-->
	<script src="../js/jquery-1.5.2.min.js" type="text/javascript"></script>
	<script src="../js/hideshow.js" type="text/javascript"></script>
	<script src="../js/jquery.tablesorter.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../js/jquery.equalHeight.js"></script>
</head>


<body>
	<?php
            require_once(__ROOT__.'\view\admin_header.php'); 
        ?>
	
	<section id="main" class="column">
            <?php
                if(isset($_GET['action']))
                {
                    if($_GET['action'] == 'succeed')
                        echo '<h4 class="alert_success">Xác nhận thành công</h4>';
                    if($_GET['action'] == 'fail')
                        echo '<h4 class="alert_error">Thất bại kiểm tra lại dữ liệu</h4>';
                }
            ?>
            <form action="<?php echo HOST ?>controller/product_controller.php?id=<?php echo $_POST['id'] ?>&image=<?php echo $_POST['image'] ?>" method="POST" enctype="multipart/form-data">
		<article class="module width_full">
			<header><h3>Sửa Sản Phẩm</h3></header>
				<div class="module_content">
						<fieldset>
							<label>Name</label>
                                                        <input type="text" name="name" value="<?php echo $_POST['name'] ?>">
						</fieldset>
						<fieldset>
							<label>Price</label>
                                                        <input type="text" name="price" value="<?php echo $_POST['price'] ?>">
						</fieldset>
                                                <fieldset>
							<label>Quantity</label>
                                                        <input type="text" name="quantity" value="<?php echo $_POST['quantity'] ?>">
						</fieldset>
						<fieldset style="width:48%; float:left; margin-right: 3%;"> <!-- to make two field float next to one another, adjust values accordingly -->
							<label>Category</label>
                                                        <select style="width:92%;" name="category">
                                                            <?php foreach($categories as $categoriess) : ?>
                                                            <?php
                                                                if($_POST['category'] == $categoriess['name'])
                                                                    echo '<option selected="'.$categoriess["name"].'" value="'.$categoriess["type"].'">'.$categoriess["name"].'</option>';
                                                                else
                                                                    echo '<option value="'.$categoriess["type"].'">'.$categoriess["name"].'</option>';
                                                            ?>                                                            
                                                            <?php endforeach; ?>
							</select>
						</fieldset>
						<fieldset style="width:48%; float:left;"> <!-- to make two field float next to one another, adjust values accordingly -->
							<label>Images</label>
                                                        <input type="file" style="width:92%; margin-left: 4px;" name="image">
						</fieldset><div class="clear"></div>
				</div>
			<footer>
				<div class="submit_link">
                                    <input type="submit" value="Action" class="alt_btn" name="update">
				</div>
			</footer>
		</article><!-- end of post new article -->
                </form>
		<div class="spacer"></div>
	</section>
</body>

</html>